package com.he.architecture.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.he.architecture.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@Where(clause = "is_deleted = 0")
//实际上架的商品
public class Item extends LogicEntity {
    @Column
    private String itemName;
    @Column
    //实际零售价
    private Double actPrice;

    //商家和上架商品的一对多
    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"items"})
    private Shop shop;

    //商品和上架商品的一对多关系
    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"items"})
    private ShopItem shopItem;

    //流水与上架商品的多对一关系
    @OneToMany(mappedBy = "item",
            fetch = FetchType.LAZY,
            orphanRemoval = true,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties(value = {"item"})
    private Set<LineItem> lineItems;
}
